package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    ImageView imageView;
    MyScrollView msv;
    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
        imageView.scrollBy(200,200); // 相对当前这个位置的内容偏移
        imageView.scrollTo(200,200); // 设置绝对偏移
        //msv.scrollTo(200,0);
    }

    private void initEvent() {
       TextView del = msv.findViewById(R.id.tv_del);
       del.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Toast.makeText(MainActivity.this, "删除", Toast.LENGTH_SHORT).show();
           }
       });
    }

    private void initView() {
        imageView = findViewById(R.id.iv_pic);
        msv = findViewById(R.id.msv);
        listView = findViewById(R.id.lv_list);
        listView.setAdapter( new MyAdapter());
    }
    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = View.inflate(MainActivity.this,R.layout.list_item,null);
            TextView del = view.findViewById(R.id.tv_del);
            del.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this, "删除", Toast.LENGTH_SHORT).show();
                }
            });

            return view;
        }
    }
}